#include "UVector.h"
#include "math.h"
TVector::TVector() {
	x = 0;
	y = 0;
	z = 0;
}

TVector::TVector ( float x, float y, float z ) {
	this->x = x;
	this->y = y;
	this->z = z;
}

float TVector::Length()
{
	return sqrt ( this->x*this->x + this->y*this->y + this->z*this->z );
}

GLfloat TVector::operator <= ( const TVector& that ) const { //Distance to other vector
	return sqrt(((this->x - that.x)*(this->x - that.x))
	           +((this->y - that.y)*(this->y - that.y))
	           +((this->z - that.z)*(this->z - that.z)));
}

float TVector::operator % ( const TVector& V2 ) const {
	return this->x*V2.x+this->y*V2.y+this->z*V2.z;
};

TVector TVector::operator - ( const TVector& vec ) const {
	return TVector ( this->x - vec.x, this->y - vec.y, this->z - vec.z );
}

TVector& TVector::operator -= ( const TVector& vec ) {
	this->x -= vec.x;
	this->y -= vec.y;
	this->z -= vec.z;
	return *this;
}

TVector TVector::operator + ( const TVector& vec ) const {
	return TVector ( this->x + vec.x, this->y + vec.y, this->z + vec.z );
}

TVector& TVector::operator += ( const TVector& vec ) {
	this->x += vec.x;
	this->y += vec.y;
	this->z += vec.z;
	return *this;
}

TVector TVector::operator * ( const TVector& vec ) const {
	return TVector ( this->y * vec.z - this->z * vec.y,
	                 this->z * vec.x- this->x * vec.z,
	                 this->x * vec.y - this->y * vec.x );
}

TVector& TVector::Normalize() {
	float Ratio = this->Length();
	this->x = this->x/Ratio;
	this->y = this->y/Ratio;
	this->z = this->z/Ratio;
	return *this;
}

TVector TVector::Normal()
{
	float Ratio = Length();
	return TVector(x/Ratio, y/Ratio, z/Ratio);
}

TVector TVector::operator* ( const int factor ) const {
	return TVector ( this->x * factor, this->y * factor, this->z * factor );
}

TVector& TVector::operator*= ( const int factor ) {
	this->x *= factor;
	this->y *= factor;
	this->z *= factor;
	return *this;
}

TVector TVector::operator* ( const float factor ) const {
	return TVector ( this->x * factor, this->y * factor, this->z * factor );
}

TVector& TVector::operator*= ( const float factor ) {
	this->x *= factor;
	this->y *= factor;
	this->z *= factor;
	return *this;
}

bool TVector::operator == ( const TVector& vec ) const {
	return ( this->x == vec.x && this->y == vec.y && this->z == vec.z );
}

TVector TVector::operator / ( const int i ) const {
	return TVector ( this->x /i, this->y/i, this->z/i );
}

